<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <!-- import CSS -->
    <link rel="stylesheet" href="https://cdn.staticfile.org/element-ui/2.15.9/theme-chalk/index.css">
    <!--    导入自己的css文件-->
    <link rel="stylesheet" href="../css/my-css.css">
    <style>
        /*设置聊天框的高度*/
        .el-dialog {
            height: 600px;
        }

        .message-list {
            display: flex;
            flex-direction: column;
            padding: 10px;
        }

        .received {
            margin-right: auto;
            max-width: 80%;
            background-color: #f2f2f2;
            border-radius: 10px;
            padding: 10px;
            margin-bottom: 10px;
        }

        .sent {
            margin-left: auto;
            max-width: 80%;
            background-color: #0066cc;
            color: #fff;
            border-radius: 10px;
            padding: 10px;
            margin-bottom: 10px;
        }

        .message-input {
            display: flex;
            flex-direction: row;
        }
    </style>
</head>
<body>
<div id="app">
    <el-container>
        <my-header></my-header>
        <el-main style="width: 1200px; height: 600px; margin: 0 auto;padding-left: 125px">
            <el-row gutter="20">
                <el-col span="4">
                    <el-card style="height: 500px">
                        <p @click="location.href='/usermodel/personal.html'" style="margin-bottom: 30px; cursor: pointer">个人信息</p>
                        <p style="color: #169FE4;margin-bottom: 30px">好友列表</p>
                        <p style="margin-bottom: 30px">笔记管理</p>
                        <p style="margin-bottom: 30px;cursor: pointer" @click="location.href='../videomodel/videoManagement.html'">视频管理</p>
                    </el-card>
                </el-col>
                <el-col span="20">
                    <el-table :data="friendsArr">
                        <el-table-column prop="nickname" label="昵称"></el-table-column>
                        <el-table-column prop="avatar" label="头像">
                            <template slot-scope="scope">
                                <el-avatar :src="scope.row.avatar"></el-avatar>
                            </template>
                        </el-table-column>
                        <el-table-column prop="status" label="状态">
                            <template slot-scope="scope">
                                <span style="color: #666666" v-if="scope.row.status==0">离线</span>
                                <span v-else>在线</span>
                            </template>
                        </el-table-column>
                        <el-table-column prop="status" label="聊天">
                            <template slot-scope="scope">
                                <el-button type="success">聊天</el-button>
                            </template>
                        </el-table-column>
                        <el-table-column prop="status" label="操作">
                            <template slot-scope="scope">
                                <el-button @click="deleteFriend(scope.$index,scope.row)" type="danger">删除好友</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                </el-col>
            </el-row>
        </el-main>
        <my-footer></my-footer>
    </el-container>
</div>
</body>
<!-- import Vue before Element -->
<script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
<!-- import JavaScript -->
<script src="https://cdn.staticfile.org/element-ui/2.15.9/index.min.js"></script>
<!--引入axios框架文件-->
<script src="https://cdn.bootcss.com/axios/0.18.0/axios.min.js"></script>
<!--导入自己的头部js文件-->
<script src="../js/my-header.js"></script>
<!--导入自己的尾部js文件-->
<script src="../js/my-footer.js"></script>
<script>
    let v = new Vue({
        el: '#app',
        data: function () {
            return {
                user:localStorage.user?JSON.parse(localStorage.user):null,
                friendsArr:[]
            }
        },
        methods: {
            deleteFriend(index,row){
                this.$confirm('您确定要删除该好友吗?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    axios.post("/v1/friends/deleteByUserAndFriendId/"+row.friendId).then(response =>{
                        if (response.data.code==20000){
                            v.friendsArr.splice(index,1);
                            location.reload();
                        }
                    })
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });

            }
        },
        created(){
            axios.get("/v1/friends/selectAllFriends/").then(response => {
                if (response.data.code==20000){
                    v.friendsArr = response.data.data;
                }else {
                    v.$message.error("请先登录");
                    location.href = "/usermodel/login.html";
                }
            })
        }
    })
</script>
</html>